package com.example.qiaoruian.shequ;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.qiaoruian.shequ.bean.TodayWeather;
import com.example.qiaoruian.shequ.view.CalendarView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * Created by qiaoruian on 2017/5/10.
 */

public class WeatherActivity extends BaseActivity implements CalendarView.OnDateChangeListener {

    private TextView mshijian01;
    private TextView nongli;
    private TextView tv01;
    private TextView tv02;
    private CalendarView calendarView;
    private ImageView iv_back;

    @Override
    public void setView() {
        setContentView(R.layout.tinaqi_fragment);
    }


    @Override
    public void initView() {
        Intent intent=getIntent();
        TodayWeather weather= (TodayWeather) intent.getSerializableExtra("bean");
        mshijian01 = (TextView) findViewById(R.id.shijian01);
        nongli = (TextView) findViewById(R.id.nongli);
        tv01 = (TextView) findViewById(R.id.tv01);
        tv02 = (TextView) findViewById(R.id.tv02);
        iv_back = (ImageView) findViewById(R.id.iv_back);
        //在代码中
        calendarView = (CalendarView) findViewById(R.id.calendar);
        //设置标注日期
        List<Date> markDates = new ArrayList<Date>();
        markDates.add(new Date());
        calendarView.setMarkDates(markDates);
        calendarView.getTitle(new Date());
        mshijian01.setText(calendarView.title);
        nongli.setText(calendarView.title2);
        tv01.setText(calendarView.title3);
        tv02.setText(calendarView.title4);

        //设置点击操作
        calendarView.setOnCalendarViewListener(new CalendarView.OnCalendarViewListener() {

            @Override
            public void onCalendarItemClick(CalendarView view, Date date) {
                // TODO Auto-generated method stub
                view.getTitle(date);
                mshijian01.setText(view.title);
                nongli.setText(view.title2);
                tv01.setText(view.title3);
                tv02.setText(view.title4);
                final SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA);
                Toast.makeText(WeatherActivity.this, format.format(date), Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void setListener() {
        calendarView.setDatechangelistener(this);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void onUpdate() {
        calendarView.updatedate();
        mshijian01.setText(calendarView.title);
        nongli.setText(calendarView.title2);
    }
}
